<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('代理商扣款规则列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label style="width: 100px;">服务商编号：</label>
                                <input type="text" name="agentNum"/>
                            </li>
                            <li>
                                <label style="width: 100px;">服务商名称：</label>
                                <input type="text" name="agentName"/>
                            </li>
                            <li>
                                <label style="width: 100px;">收款账户编号：</label>
                                <input type="text" name="proAgentNum"/>
                            </li>
                            <li>
                                <label style="width: 100px;">机具类型：</label>
                                <select id="posType" name="posType" class="form-control noselect2 selectpicker" th:with="type=${@dict.getType('terminal_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 100px;">扣款类型：</label>
                                <select id="deductionType" name="deductionType" class="form-control noselect2 selectpicker" th:with="type=${@dict.getType('deduction_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                          <!--  <li>
                                <label style="width: 100px;">审核状态：</label>
                                <select name="auditStatus" class="form-control noselect2 selectpicker" th:with="type=${@dict.getType('audit_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>-->
                            <li class="select-time">
                                <label style="width: 100px;">生成日期：</label>
                                <input type="text" class="time-input"  readonly placeholder="开始时间" name="begin_valid"/>
                                <span>-</span>
                                <input type="text" class="time-input"  readonly placeholder="结束时间" name="end_valid"/>
                            </li>
                            <li>
                                <label style="width: 10px;"></label>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()" ><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="finance:agentDeductions:add">
                    <i class="fa fa-plus"></i> 添加代理扣款
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="finance:agentDeductions:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <!--<a class="btn btn-primary single disabled" onclick="upadd()" shiro:hasPermission="finance:agentDeductions:upadd">
                    <i class="fa fa-edit"></i> 上传
                </a>
                <a class="btn btn-success multiple disabled" id="audits" onclick="audits()" shiro:hasPermission="finance:agentDeductions:audit">
                    <i class="fa fa-save"></i> 审核
                </a>-->
                <a class="btn btn-success multiple disabled" onclick="exitAccount()" shiro:hasPermission="finance:agentDeductions:account">
                    <i class="fa fa-edit"></i> 设置收款账户
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" class="table text-nowrap"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var datas = [[${@dict.getType('terminal_type')}]];
        var datas2 = [[${@dict.getType('deduction_type')}]];
        var datas3 = [[${@dict.getType('audit_status')}]];
        var datas4 = [[${@dict.getType('deductionStatus')}]];
        var editFlag = [[${@permission.hasPermi('finance:agentDeductions:edit')}]];
        var detailFlag = [[${@permission.hasPermi('finance:agentDeductions:detail')}]];
        var removeFlag = [[${@permission.hasPermi('finance:agentDeductions:remove')}]];
        var prefix = ctx + "finance/agentDeductions";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "代理商扣款规则",
                firstLoad:false,
                clickToSelect:true,
                columns: [{
                    radio: true,
                },
                    {
                        field: 'id',
                        title: '序号'
                    },
                {
                    field: 'agentNum',
                    title: '服务商编号'
                },
                {
                    field: 'agentName',
                    title: '服务商名称'
                },
                {
                    field: 'posType',
                    title: '机具类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'posNumber',
                    title: '机具数量'
                },
                {
                    field: 'deductionType',
                    title: '扣款类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas2, value);
                    }
                },
                {
                    field: 'ratio',
                    title: '扣款比例（%）'
                },
                {
                    field: 'deductionMoney',
                    title: '扣款金额（总元）'
                },
                {
                    field: 'deductionMoneyD',
                    title: '剩余扣款金额'
                },
                {
                    field: 'deductionMoneyK',
                    title: '已扣除金额'
                },
                {
                    field: 'deductionStatus',
                    title: '扣还状态',
                    formatter: function (value, row, index){
                        return $.table.selectDictLabel(datas4, value);
                    }
                },
                {
                    field: 'addMan',
                    title: '添加人编号'
                },
                {
                    field: 'note',
                    title: '扣款用途'
                },
                {
                    field: 'proAgentNum',
                    title: '收款账户编号'
                },
               /* {
                    field: 'proYlId',
                    title: '收款团长编号'
                },*/
                {
                    field: 'addDate',
                    title: '生成日期'
                },
             /*   {
                    field: 'auditStatus',
                    title: '审核状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas3, value);
                    }
                },*/
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="edit(\''+row.id+'\',\''+row.auditStatus+'\')"><i class="fa fa-edit"></i>修改</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="queryDetails(\''+row.id+'\')""><i class="fa fa-edit"></i>查看详情</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="deletes(\''+row.id+'\',\''+row.auditStatus+'\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /**
         * 查看当前详情
         * @param serial
         */
        function queryDetails(serial) {
            $.modal.openTab("查看详情","finance/agentDeductionsDetails?serial="+serial);
        }

        function upadd(){
            var id = $.table.selectColumns("id")
            var auditStatus = $.table.selectColumns("auditStatus")
            if(auditStatus == 2){
                $.modal.alertWarning("该条数据已审核成功！");
                return;
            } else if(auditStatus == 1){
                $.modal.alertWarning("该条数据已上传！");
                return;
            }
            $.modal.confirm("确定上传该条数据吗？", function() {
                var url = prefix + "/upadd"
                var data = {"ids": id[0] };
                $.operate.submit(url, "post", "json", data);
            });
        }

        function audits(){
            var id = $.table.selectColumns("id")
            var auditStatus = $.table.selectColumns("auditStatus")
            if(auditStatus == 3 || auditStatus == 0){
                $.modal.alertWarning("未上传无法进行审核！");
                return;
            }else if(auditStatus == 2){
                $.modal.alertWarning("该条数据已审核成功！");
                return;
            }
            $.modal.open("审核" , prefix+"/audits?id="+id, '500');
        }

        function exitAccount(){
            var id = $.table.selectColumns("id")
            $.modal.open("设置收款账户" , prefix+"/exitAccount?id="+id, 1100, 650);
        }

        function edit(id,auditStatus){
            $.operate.edit(id);
        }

        function deletes(id,auditStatus){
            $.operate.remove(id);
        }

    </script>
</body>
</html>